package com.hqd.ch03.v13.beans.propertyeditors;

import java.beans.PropertyEditorSupport;

public class CustomNumberEditor extends PropertyEditorSupport {
    private Class<?> numberClass;

    public CustomNumberEditor(Class<?> numberClass) {
        this.numberClass = numberClass;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if (numberClass == Integer.class || numberClass == int.class) {
            this.setValue(Integer.parseInt(text));
        } else if (numberClass == Double.class || numberClass == double.class) {
            this.setValue(Double.parseDouble(text));
        }
    }
}
